# -*- coding: utf-8 -*-
# @Time    : 2024/8/30 16:47
# @Author  : qd
# @Email   : 1518603573@qq.com
# @File    : chance_page.py
# @Software: PyCharm
from pages.base_page import BasePage
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.alert import Alert
"""添加付款单界面"""
class ChancePage(BasePage):
    url="/crm/index.php?m=business"
    # 添加商机定位器
    chance_btn_add_locator = (By.CSS_SELECTOR, "body > div.container > div.row > div:nth-child(1) > div > a")
    # 要删除的商机定位器
    chance_select_locator=(By.CSS_SELECTOR,"#form1 > table > tbody > tr:nth-child(1) > td:nth-child(1) > input")
    # 删除所有的定位器
    chance_select_all_locator = (By.ID, "check_all")
    # 删除按钮定位器
    chance_btn_delete_locator=(By.ID,"delete")
    # 搜索条件定位器
    chance_search_select_locator = (By.ID, "field")
    # 搜索关键字定位器
    chance_search_input_locator = (By.ID, "search")
    # 搜索按钮
    chance_search_btn_locator = (By.ID, "dosearch")
    # 商机名定位器
    chance_name_locator=(By.CSS_SELECTOR,"#form1 > table > tbody > tr:nth-child(1) > td:nth-child(4) > a > span")
    # 搜索为空后的页面定位器
    chance_after_select_locator=(By.CSS_SELECTOR,"#form1 > table > tbody > tr > td")
    """点击添加商机"""
    def click_chance_btn_add(self):
        self.driver.find_element(*self.chance_btn_add_locator).click()

    """选中要删除的商机"""
    def click_chance_select(self):
        self.driver.find_element(*self.chance_select_locator).click()
    """选中所有要删除的商机"""
    def click_chance_select_all(self):
        self.driver.find_element(*self.chance_select_all_locator).click()
    """点击删除按钮"""
    def click_chance_btn_delete(self):
        self.driver.find_element(*self.chance_btn_delete_locator).click()

    """确定警告框"""
    def click_chance_alert(self):
        self.driver.switch_to.alert.accept()

    """在搜索框中选择搜索条件,用文本的方式"""
    def chance_search_select(self,chance_text):
        search_element=self.driver.find_element(*self.chance_search_select_locator)
        search_select = Select(search_element)
        search_select.select_by_visible_text(chance_text)

    """在关键字条件框中输入关键字"""
    def input_chance_search(self,chance_keywords):
        self.driver.find_element(*self.chance_search_input_locator).send_keys(chance_keywords)

    """点击搜索按钮"""
    def click_chance_search_btn(self):
        self.driver.find_element(*self.chance_search_btn_locator).click()
    """获取搜索后的商机名"""
    def get_chance_name(self):
        return self.driver.find_element(*self.chance_name_locator).text.strip()
    """获取搜索为空的文本"""
    def get_after_search_text(self):
        return self.driver.find_element(*self.chance_after_select_locator).text.strip()